package com.xbongbong.paas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 版本类型 1：设计 2：启用 3：历史
 * 阶段流程版本类型
 * @author 李少杰
 * @version v1.0.0
 * @date 2021/11/18 15:54
 */
@Getter
public enum StageProcessVersionTypeEnum {

    /**
     * 设计
     */
    DESIGN(1, "enum.stage.process.name.stage_version_type_design"),
    /**
     * 启用
     */
    ENABLE(2, "enum.stage.process.name.stage_version_type_enable"),
    /**
     * 历史
     */
    HISTORY(3, "enum.stage.process.name.stage_version_type_history");

    /**
     * 版本code
     */
    private final int code;
    /**
     * 描述
     */
    private final String name;

    StageProcessVersionTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public static StageProcessVersionTypeEnum getTypeByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (StageProcessVersionTypeEnum stageProcessVersionTypeEnum : StageProcessVersionTypeEnum.values()) {
            if (Objects.equals(stageProcessVersionTypeEnum.getCode(), code)) {
                return stageProcessVersionTypeEnum;
            }
        }
        return null;
    }

}
